package com.example.utils;

import java.util.HashMap;

public class ResultUtils {
    /**
     * 返回带数据的信息
     * @param obj
     * @return
     */
    public static Result success(Object obj){
        Result result=new Result();
        result.setSuccess(true);
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMsg(ResultEnum.SUCCESS.getMsg());
        result.setData(obj);
        return result;
    }

    /**
     * 返回成功但不带数据
     * @return
     */
    public static Result success(){
        return success(null);
    }

    /*返回成功数据
    */

    public static Result success(Object obj1, Object obj2) {
        HashMap<Object, Object> map = new HashMap<>();
        map.put(obj1, obj2);
        Result result = new Result();
        result.setData(map);
        result.setSuccess(true);
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMsg(ResultEnum.SUCCESS.getMsg());
        return result;
    }

    /** 设置响应失败。 */

    public static Result error(ResultEnum resultEnum){
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(ResultEnum.ERROR.getCode());
        result.setMsg(ResultEnum.ERROR.getMsg());
        return result;
    }

    public static Result error(Integer code,String msg){
        Result result=new Result();
        result.setSuccess(false);
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
}
